package xtgl;

import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import xtgl.Privilege;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;

public class PrivilegeController extends Controller {
	
	public static int pagen=10;
	public static String qxmc="";
	public static String qxbh="";

	public void index() {
		pagen=10;
		qxmc="";
		qxbh="";
		setAttr("list", Privilege.dao.getPrivilege());
		render("/xtgl/qxgl.html");
	}

	public void sele() {
		qxmc=getPara("qxmc");
		qxbh=getPara("qxbh");
		renderNull();
	}

	public void pagedemo() {
		List<Object> listpri=new ArrayList<Object>();
		Map<String, Object> map=new HashMap<String, Object>();
		List<Privilege> privileges=Privilege.dao.find("select * from privilege");
		int n = getParaToInt("pageNumber", 1);
		
		if(qxmc==""&&qxbh==""){
			Page<Privilege> list = Privilege.dao.paginate(n, pagen, "select *",
					"from privilege");
			map.put("privileges", privileges);
			map.put("list", list);
			listpri.add(map);
			renderJson(listpri);
		}else if(qxmc!=""&&qxbh==""){
			Page<Privilege> list = Privilege.dao.paginate(n, pagen, "select *",
					"from privilege where privilege_name like '%"+ qxmc+"%' ");
			map.put("privileges", privileges);
			map.put("list", list);
			listpri.add(map);
			renderJson(listpri);
		}else if(qxmc==""&&qxbh!=""){
			Page<Privilege> list = Privilege.dao.paginate(n, pagen, "select *",
					"from privilege where privilege_id like '%"+ qxbh+"%' ");
			map.put("privileges", privileges);
			map.put("list", list);
			listpri.add(map);
			renderJson(listpri);
		}else{
			Page<Privilege> list = Privilege.dao.paginate(n, pagen, "select *",
					"from privilege where privilege_id like '%"+ qxbh+"%' and  privilege_name like '%"+ qxmc+"%'");
			map.put("privileges", privileges);
			map.put("list", list);
			listpri.add(map);
			renderJson(listpri);
		}

	}
	
	//更改每一页显示的行数
	public void gghs(){
		pagen=getParaToInt("pagen");
		renderText("success");
	}
}
